#!/bin/bash
# this script is used on hack.p6c.org as the 'doc.perl6.org' user to update
# the website.
source /home/rakudobrew/.rakudobrew-bash
set -e
set -x
cd ~/doc
git fetch
before=$(git rev-parse HEAD)
git checkout origin/master
after=$(git rev-parse HEAD)
if [ ! -f "$HOME/force-update" ] ; then
    if [ "$before" = "$after" ] ; then
        echo "nothing to do"
        exit
    fi
fi

rm "$HOME/force-update" || true;
LOGDIR=$HOME/doc/html/build-log
mkdir -p "$LOGDIR"
DATE=$(date --iso-8601=minutes)
LOGFILE="$LOGDIR/build-$DATE.log";
echo "Writing logs to $LOGFILE";
exec >$LOGFILE 2>&1

echo "Building docs for $after with " `perl6 --version`
echo 'Cleaning out old HTML files'
# don't clean out html/ entirely, because there are some files
# under version control there, and because  of html/build-log/
find html/ -name '*.html' -delete

# if the htmlify fails, sync the build log.
# since sync-build-log returns false, not the whole thing is synced
time make html || ./util/sync-build-log
./util/sync

# vim: expandtab shiftwidth=4
